﻿@model PagingDataSet<Comment>
@{
    var tenantTypeId = ViewData.Get<string>("tenantTypeId", string.Empty);
    var commentedObjectId = ViewData.Get<long>("commentedObjectId", 0);
    var currentUser = UserContext.CurrentUser;
    var pageIndex = Model.PageIndex;
    var count = ViewData.Get<long>("count", 0);
    pageIndex--;
}
<div class="tn-chat-list">
    @Html.Hidden("tenantTypeId", tenantTypeId)
    @Html.Hidden("commentedObjectId", commentedObjectId)
    @if (Model.Any())
    {
        var cn = 0;
        foreach (var item in Model)
        {
            cn++;
            <div class="media">
                <div class="media-left">
                    @Html.ShowUserAvatar(userId: item.UserId, avatarSizeType: AvatarSizeType.Micro)
                </div>
                <div class="media-body">
                    <h4 class="media-heading"><small class="pull-right">#@(pageIndex * 10 + cn)</small><a target="_blank" href="@SiteUrls.Instance().SpaceHome(item.UserId)">@item.Author</a></h4>
                    <p class="message">@Html.Raw(item.Body)</p>
                    <div class="tn-feedback">
                        <small class="pull-left text-muted">@item.DateCreated.ToFriendlyDate()</small>
                        <ul class="list-inline text-right text-muted" onmouseover="$.fn.showoperation(this);" onmouseout="$.fn.hideoperation(this);">
                            <li>
                                @if (currentUser != null)
                                {
                                    if (currentUser.UserId == item.UserId)
                                    {
                                    <a href="javascript:;" id="commentdelete-@item.Id" style="display:none"><i class="fa fa-trash"></i> 删除</a>
                                    }
                                    <a id="commentcreate-@item.Id" href="javascript:;" data-href="@SiteUrls.Instance()._Comment(item.Id, tenantTypeId, commentedObjectId)"><i class="fa fa-reply"></i> 回复</a><text>&nbsp;</text>
                                }
                            </li>
                        </ul>
                    </div>
                    @if (item.ChildrenCount > 0)
                    {
                    @Html.Action("_ChildComment", "Portal", new { parentId = item.Id, commentedObjectId = commentedObjectId, tenantTypeId = tenantTypeId })
                    }
                </div>
            </div>
        }

        <div class="text-center">
            @Html.AjaxPagingButton(Model, "CommentLists", CachedUrlHelper.Action("_ListComment", "Portal", null, new RouteValueDictionary { { "commentedObjectId", commentedObjectId }, { "tenantTypeId", tenantTypeId } }))
        </div>
    }
    else
    {
    <div class="media">
        <div class="media-body text-center text-warning">
            <h4 class="media-heading">暂无评论</h4>
        </div>
    </div>
    }
</div>
<script type="text/javascript">
    require(['jquery', 'tnlayer', 'qqFace','page'], function ($) {
        $.fn.showoperation = function (e) {
            var commentdel = $(e).find("a");
            if (commentdel.length > 1) {
                commentdel[0].style.display = "inline";
            }
        }
        $.fn.hideoperation = function (e) {
            var commentdel = $(e).find("a");
            if (commentdel.length > 1) {
                commentdel[0].style.display = "none";
            }
        }
        $(function myfunction() {
            var TotalRecords = @Model.TotalRecords;
            var AuditCount =   parseInt(@count)-parseInt( TotalRecords);
            $("#AuditCount").html("审核中("+AuditCount+")");

        })
    })
</script>